package classmate.view;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

public class AFrame extends JFrame implements ActionListener{
	private static final long serialVersionUID = 1L;
	JLayeredPane backgroundjpl;
	JPanel jplNorth,jplCenter,jplbackground;
	JButton jbt1,jbt2;
	JLabel jlb,jlb1,jlb2;
	ImageIcon backgroungimage,insertimage;
	
	public AFrame(String str) {
		super(str);
		jlb1 = new JLabel("欢迎使用同学通讯录");
		backgroundjpl = new JLayeredPane();
		backgroungimage = new ImageIcon("res/hua.jpg");
		insertimage = new ImageIcon("image/cover.png");
		jplbackground = new JPanel();
		jplNorth = new JPanel();
		jplCenter = new JPanel();
		jbt1 = new JButton("进入");
		jbt1.addActionListener((ActionListener) this);
		jbt2 = new JButton("退出");
		jbt2.addActionListener(this);
		jlb = new JLabel(backgroungimage);
		jlb2 = new JLabel(insertimage);
		
		jplbackground.setSize(backgroungimage.getIconWidth(),backgroungimage.getIconHeight());
		jlb.setSize(backgroungimage.getIconWidth(),backgroungimage.getIconHeight());
		jplbackground.add(jlb);
		
		jplCenter.setSize(insertimage.getIconWidth(),insertimage.getIconHeight());
		jlb2.setSize(insertimage.getIconWidth(),insertimage.getIconHeight());
		jplCenter.add(jlb2);
		
		Font f = new Font("宋体",1,50);
		Font f1 = new Font("楷体",1,60);
		jbt1.setFont(f);
		jbt1.setBackground(new Color(222,233,202));
		jbt2.setFont(f);
		jbt2.setBackground(new Color(222,233,202));
		jlb1.setFont(f1);
		
		jbt1.setBounds(80,500,200,80);
		jbt2.setBounds(80,600,200,80);
		jplCenter.setBounds(670,350,insertimage.getIconWidth(),insertimage.getIconHeight());
		jplNorth.add(jlb1);
		jplNorth.setBackground(new Color(224,237,209));
		jplNorth.setBounds(220,90,600,120);
		
		backgroundjpl.add(jplbackground,JLayeredPane.DEFAULT_LAYER);
		backgroundjpl.add(jplNorth,JLayeredPane.MODAL_LAYER);
		backgroundjpl.add(jplCenter,JLayeredPane.MODAL_LAYER);
		backgroundjpl.add(jbt1,JLayeredPane.MODAL_LAYER);
		backgroundjpl.add(jbt2,JLayeredPane.MODAL_LAYER);
		this.pack();
		this.setLayeredPane(backgroundjpl);
		this.setBounds(700,500,backgroungimage.getIconWidth(),backgroungimage.getIconHeight());
		this.setSize(1000, 800);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setResizable(false);
		this.setLocationRelativeTo(null);//设置null可以将该窗口位置放置在屏幕中间
		this.setVisible(true); 
	}
	
    public void actionPerformed(ActionEvent e) {
    	if(e.getActionCommand()=="退出")
		{
			System.exit(0);
		}
		else if(e.getActionCommand()=="进入")
		{
			this.dispose();  //关闭当前界面
			StudentFrame F=new StudentFrame();   //打开新界面
			F.setLocationRelativeTo(null);
		}
	}

}
